#ifndef HANDLE_MANAGE_H
#define HANDLE_MANAGE_H
#pragma execution_character_set("utf-8")
#include <handle.h>
#include <QObject>
#include <QSharedPointer>
#include <QMap>
#include <QThread>
class handle_manage : public QObject
{
    Q_OBJECT
public:
    handle_manage();
    ~handle_manage();
    void setHandleCount(int handleNum);                    //设置处理线程数量
    void init();                                           //开始生成对应数量的handle
private:
    int handle_count=2;
    QMap<Handle*,QThread*>     thread_map;
    QMap<Handle*,int>                         thread_task_num;
    Handle* Choice_Free_Handle();             //选择负载小的处理线程
private slots:
    void receive(QString id,QString type,QString data);      //接受来自socket或者localsocket的信息
    void Cl_SocketSendData(QString id,QString type,QString data,local_socket *l_socket,emit_type te_ype,QString socketType);    //转发来自处理线程的信息
    void Ct_SocketSendData(QString id,QString type,QString data,tcp_socket *t_socket,emit_type te_ype,QString socketType);      //转发来自处理线程的信息

signals:
    void l_SocketSendData(QString id,QString type,QString data,local_socket *l_socket,emit_type te_ype,QString socketType);     //发送给localsocket信息
    void t_SocketSendData(QString id,QString type,QString data,tcp_socket *t_socket,emit_type te_ype,QString socketType);       //发送给tcpsocket信息
    void Handlelocaldata(QString id,QString type,QString data,local_socket *l_socket,Handle *handle,emit_type te_ype);                       //发送给处理线程来自localsocket的信息
    void Handletcpdata(QString id,QString type,QString data,tcp_socket *t_socket,Handle *handle,emit_type te_ype);                           //发送给处理线程来自tcpsocket的信息
};

#endif // HANDLE_MANAGE_H
